package com.qd.common.panda.domain.entity.card.collect;

import com.cdqidi.util.page.BaseQuery;
import com.cdqidi.valid.group.DefaultGroup;
import com.cdqidi.valid.group.DeleteGroup;
import com.cdqidi.valid.group.UpdateGroup;
import com.qd.common.panda.domain.entity.card.CardInfoDTO;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import java.util.Optional;


/**
 * 劵关系
 *
 * @author sjk
 */
@EqualsAndHashCode(callSuper = true)
@Getter
@Setter
public class CollectCardRelationDTO extends BaseQuery {

    /**
     * 主键
     */
    @NotBlank(message = "关系ID不能为空", groups = {DeleteGroup.class, UpdateGroup.class})
    @Size(max = 50, message = "关系ID长度不能超过{max}位", groups = {DeleteGroup.class, UpdateGroup.class})
    private String relationId;
    /**
     * 领劵ID
     */
    @NotBlank(message = "领劵ID不能为空", groups = DefaultGroup.class)
    @Size(max = 50, message = "领劵ID长度不能超过{max}位", groups = DefaultGroup.class)
    private String cid;
    /**
     * 劵信息
     */
    @NotBlank(message = "劵信息不能为空", groups = DefaultGroup.class)
    @Size(max = 50, message = "劵信息长度不能超过{max}位", groups = DefaultGroup.class)
    private String cardMsgId;
    /**
     * 推广码
     */
    @NotBlank(message = "推广码不能为空", groups = DefaultGroup.class)
    @Size(max = 50, message = "推广码长度不能超过{max}位", groups = DefaultGroup.class)
    private String promotionCode;
    /**
     * 卷数量
     */
    private Integer cardQuantity;
    /**
     * 可用数量
     */
    private Integer availableQuantity;
    /**
     * 券信息
     */
    private CardInfoDTO cardInfo;

    @Override
    public void freeData() {
        this.relationId = null;
        this.cid = null;
        this.cardMsgId = null;
        this.promotionCode = null;
        this.cardQuantity = null;
        this.availableQuantity = null;
        Optional.ofNullable(cardInfo).ifPresent(CardInfoDTO::freeData);
        super.freeData();
    }
}
